#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 150;
string inv[N];
unordered_map<string, int> h = {
    {"BangZhong", 1},
    {"BangZhu", 7},
    {"FuBangZhu", 6},
    {"HuFa", 5},
    {"JingYing", 2},
    {"TangZhu", 3},
    {"ZhangLao", 4}
};
struct person {
    string name, zhiwei1;
    int banggong, degree, appear;
    person(string n, string z1, int bg, int d, int a)
        : name(n), zhiwei1(z1), banggong(bg), degree(d), appear(a) {}
};
vector<person> p;
bool compareone(const person &a, const person &b)
{
    if(a.banggong != b.banggong) return a.banggong > b.banggong;
    return a.appear > b.appear;
}
bool comparetwo(const person &a, const person &b)
{
    if(h[a.zhiwei1] != h[b.zhiwei1]) return h[a.zhiwei1] > h[b.zhiwei1];
    if(a.degree != b.degree) return a.degree > b.degree;
    return a.appear > b.appear;
}
int cnt = 155;
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string a, b, c, d;
        cin >> a >> b >> c >> d;
        p.push_back(person(a, b, stoi(c), stoi(d), cnt--));
    }
    sort(p.begin(), p.end(), compareone);
    int k = 1;
    for(auto &a : p) {
        if(h[a.zhiwei1] >= 6 || a.name == "absi2011") {
            continue;
        }
        if(k < 3) {
            a.zhiwei1 = "HuFa";
        }else if(k < 7) {
            a.zhiwei1 = "ZhangLao";
        }else if(k < 14) {
            a.zhiwei1 = "TangZhu";
        }else if(k < 39) {
            a.zhiwei1 = "JingYing";
        }else {
            a.zhiwei1 = "BangZhong";
        }
        k++;
    }
    sort(p.begin(), p.end(), comparetwo);
    for(auto& a : p) {
        cout << a.name << " " << a.zhiwei1 << " " << a.degree << endl;
    }
    return 0;
}